<?php
/**
 * Created by PhpStorm.
 * User: hui
 * Date: 2017/2/26
 * Time: 16:40
 */
namespace app\admin\logic;

use app\common\traits\Password;

class Login
{
    use Password;

    protected $admin;

    public function check($post)
    {
        //验证数据
        $valid = validate('Admin');
        if (!$valid->scene('login')->check($post)){
            return $valid->getError();
        }
        //查询用户
        $map = [
            'name' => $post['name']
        ];
        $this->admin = db('admin')
            ->where($map)
            ->find();
        if (empty($this->admin)){
            return false;
        }
        //检查密码
        $this->passwordHash = $this->admin['password'];
        return $this->passwordVerify($post['password']);
    }

    public function getAdmin()
    {
        return $this->admin;
    }
}